/*
  S.M.A.C.K - An operating system kernel
  Copyright (C) 2010,2011 Mattias Holm and Kristian Rietveld
  For licensing and a full list of authors of the kernel, see the files
  COPYING and AUTHORS.
*/

#ifndef KERNEL__SYSCALL_H
#define KERNEL__SYSCALL_H

#include <stdint.h>
#include <stddef.h>
#include <sys/types.h>
#include <sys/proc.h>
#include <time.h>

#define SYS_sleep 1
struct sys_sleep
{
  int seconds;
};

#define SYS_opendir 2
struct sys_opendir
{
  char name[256];
};

#define SYS_readdir 3
struct sys_readdir
{
  int handle;

  /* output parameters: */
  int type;
  char name[256];
  int size;
};

#define SYS_closedir 4
struct sys_closedir
{
  int handle;
};

#define SYS_exit 5
struct sys_exit
{
  int exit_code;
};

#define SYS_open 6
struct sys_open
{
  char name[256];
};

#define SYS_read 7
struct sys_read
{
  int handle;
  /* FIXME: limited to 256 for now, also, we do not want to copy
   * the buffer into the structure ideally.  ARM can read from user
   * memory directly, so no copy is required (efficient!) for x86,
   * we need a copy from user to kernel memory already.
   */
  void *buff[256];
  size_t nbytes;
};

#define SYS_write 8
struct sys_write
{
  int handle;
  /* FIXME: limited to 256 for now, also, we do not want to copy
   * the buffer into the structure ideally.  ARM can read from user
   * memory directly, so no copy is required (efficient!) for x86,
   * we need a copy from user to kernel memory already.
   */
  void *buff[256];
  size_t nbytes;
};

#define SYS_close 9
struct sys_close
{
  int handle;
};

#define SYS_seek 10
struct sys_seek
{
  int handle;
  off_t offset;
  int whence;
};

#define SYS_fork 11

#define SYS_execve 12
struct sys_execve
{
  char filename[256];
  char argv[256]; /* Can be extended up to 4096 for now */
};

#define SYS_stat 13
struct sys_stat
{
  char name[256];

  /* output parameters: */
  int type;
  int size;
};

#define SYS_wait 14
struct sys_wait
{
  /* output parameters: */
  int exit_code;
};

#define SYS_chdir 15
struct sys_chdir
{
  char directory[256];
};

#define SYS_getwd 16
struct sys_getwd
{
  /* output parameters: */
  char directory[256];
};

#define SYS_mount 17
struct sys_mount
{
  char fs[32];
  char mountpoint[256];
};

/* FIXME: A quick-and-dirty system call until we have something like
 * a /proc file system in place.  We limit this to 32 processes.
 */
#define SYS_get_processes 18
struct sys_get_processes
{
  /* output parameters: */
  uint32_t n_processes;
  struct
    {
      pid_t pid;
      uint32_t cpu_time;
    }
  processes[32];
};

#define SYS_ioctl 19
struct sys_ioctl
{
  int handle;

  uint32_t request;
  uint32_t param;
};

#define SYS_mmap 20
struct sys_mmap
{
  void *retval;
  void *addr;
  size_t len;
  int prot;
  int flags;
  int fd;
  off_t offset;
};

#define SYS_munmap 21
struct sys_munmap
{
  void *addr;
  size_t len;
};

#define SYS_clock_gettime 22
struct sys_clock_gettime
{
  clockid_t clk_id;
  struct timespec *tp;
};

#define SYS_clock_settime 23
struct sys_clock_settime
{
  clockid_t clk_id;
  const struct timespec *tp;
};

#define SYS_setprocparam 24
struct sys_setprocparam
{
  proc_param_t param;
  int64_t value;
};

#define SYS_getprocparam 25
struct sys_getprocparam
{
  proc_param_t param;
  int64_t result;
};

#define SYS_mkdir 26
struct sys_mkdir
{
  char name[256];
};

#define SYS_rmdir 27
struct sys_rmdir
{
  char name[256];
};

#endif /* KERNEL_SYSCALL_H */
